<!DOCTYPE HTML>
<html>

<head>
    <title>Eas-JTest</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link href="/static/images/favicon.ico" rel="shortcut icon">
    <script type="text/javascript" src="/static/jquery/jquery-3.6.0.min.js"></script>
    <style>
        nav {
            width: 100%;

            margin-top: 60px;
        }

        nav p {
            width: 750px;
            height: 35px;
            line-height: 35px;
            margin: 8px auto;
        }

        .logo {
            text-align: center;
        }

        .logo img {
            width: 215px;
            height: 110px;
        }

        .search {
            width: 750px;
            height: 50px;
            margin: auto;
            display: flex;
            justify-content: center;
            align-content: center;
            min-width: 750px;
            position: relative;
        }

        input {
            width: 550px;
            height: 40px;
            border-right: none;
            border-bottom-left-radius: 10px;
            border-top-left-radius: 10px;
            border-color: #f5f5f5;
            outline: none;
        }

        input:hover {
            box-shadow: 2px 2px 2px #ccc;
        }

        input:focus {
            border-color: rgb(78, 110, 242);
        }

        .search span {
            position: absolute;
            font-size: 23px;
            top: 10px;
            right: 170px;
        }

        .search span:hover {
            color: rgb(78, 110, 242);
        }

        button {
            width: 100px;
            height: 44px;
            background-color: rgb(78, 110, 242);
            border-bottom-right-radius: 10px;
            border-top-right-radius: 10px;
            border-color: rgb(78, 110, 242);
            color: white;
            font-size: 14px;
        }
        #ranking_list {
            width: 750px;
            height: 100%;
            overflow: hidden;
            display: flex;
            flex-direction: column;

            margin-inside: 18px auto;
        }
        input.red{background:#ffe9e8;}
    </style>
    <script type="text/javascript">
        //闪动
        function shake(ele,cls,times){
            ele.css("border", "1px solid #ef4136");
            var i = 0,t= false ,o =ele.attr("class")+" ",c ="",times=times||2;
            if(t) return;
            t= setInterval(function(){
                i++;
                c = i%2 ? o+cls : o;
                ele.attr("class",c);
                if(i==2*times){
                    clearInterval(t);
                    -
                    ele.removeClass(cls);
                    ele.css("border", "");
                }
            },200);
        };

        $(document).ready(function(){
            $("#search_click").click(function(){
                var search_txt = $("#search_txt").val();
                if (search_txt==""){
                    shake($("#search_txt"),"red",3);
                }else {
                    $.ajax({
                        url:"/search",
                        type:"POST",
                        dataType:"json",
                        data:{"beanName":search_txt},
                        beforeSend:function(xhr){
                            $("#bang").empty();
                            $("#beanName").html("");
                            $("#bang").attr("style","display:none;");
                            $("#ranking_list").attr("style","display:none;");
                            console.log("before send");
                        },
                        success:function(data){
                            console.log(data);
                           if (data.code=="404"){
                               $("#ranking_list").attr("style","display:'';");
                               alert(data.message);
                               $("#beanName").html(data.message);
                           }else if (data.code==200){
                               $("#ranking_list").attr("style","display:'';");
                               $("#bang").attr("style","display:'';height: 300px;width: 650px;border: 2px rgb(78, 110, 242) solid; overflow: auto; padding-left:10px; right: 170px;");
                               $("#beanName").html(data.data.beanName);
                               alert(data);
                               var beanInfos = data.data.methods;
                               if (beanInfos==null){
                                   $("#bang").append("<p>"+data.data.beanName+" not find method!</p>");
                               }else {
                                   var html ="";
                                   $.each(beanInfos,function(index,obj){  //index:索引obj:循环的每个元素
                                       var parameter = obj.parameterList;
                                        html += "<a href='' onclick=\"return false;\"> "+obj.methodName+"(";
                                       if (parameter!=null||parameter.length!=0) {
                                           var parameterVal = "";
                                           $.each(parameter, function (index1, obj1) {
                                               html += obj1.parameterType + " " + obj1.parameterName;
                                               parameterVal += obj1.parameterType;
                                               if (index1 <= parameter.length - 2) {
                                                   html += ",";
                                                   parameterVal +=",";
                                               }
                                           });
                                           html += ") <input type=\"hidden\"  value=\""+parameterVal+"\"> </a>";
                                           html +=  "<br/><br/>";
                                       }

                                   });
                                   $("#bang").append(html);
                               }

                           }
                        },
                        error:function(){
                            console.log("请求error");
                        },
                        complete:function(xhr){
                            console.log("complete");
                            console.log(xhr);
                        },
                        timeout:function () {
                            console.log("response time out!");
                        }
                    })
                }


            });

        });

        $(function () {
            $("#bang").on("click", "a", function () {
                alert($(this).children("input").val());
                $.post("/middleman",
                    {
                        beanName:"Donald Duck",
                        methods:"Duckburg"
                    },
                    function(data){
                        window.open("/middleman")
                    });



            });
            // $("#bang").on("click", function() {
            //     var str2 = $("#bang").children("a").val();
            //     alert(str2);
            // });

        });

    </script>
</head>

<body>


<!-- Main -->
<div id="main">
    <nav>
        <div class="logo">
            <h2 class="Hero-title"><i class="icon fas fa-exclamation-triangle"></i> Easy JTest</h2>
        </div>
        <div class="search">
            <input id="search_txt" type="text" placeholder="Please enter java bean name! Make java test simple!">
            <button id="search_click">search</button>
        </div>
    </nav>
</div>
</br>
</br>
</br>

    <#if beanIsExist ==0>
        <#if errMsg??  && errMsg!= "">
            <div id="ranking_list" style="display:'';">
                <p id="beanName"> ${errMsg}</p>
                <div id="bang"  style="display:'';">
                </div>
            </div>
        <#else>
            <div id="ranking_list" style="display:none;">
                <p id="beanName"></p>
                <div id="bang"  style="display:none;">

                </div>
            </div>
        </#if>
    <#else>
        <div id="ranking_list" style="display:'';">
            <p id="beanName"> ${beanName}</p>
            <div id="bang"  style="display:'';height: 300px;width: 650px;border: 2px rgb(78, 110, 242) solid; overflow: auto; padding-left:10px; right: 170px;">
                ${beanInfos}
            </div>
        </div>
    </#if>


</body>

</html>